#!/usr/bin/perl
#^^^^^^^^^^^^^^ Change this to the location of Perl                           #
###############################################################################
# SuperLinks                                                                  #
# Copyright (c) 2000-2007 Greg Nolle (http://greg.nolle.co.uk)                #
###############################################################################
# This program is free software; you can redistribute it and/or modify it     #
# under the terms of the GNU General Public License as published by the Free  #
# Software Foundation; either version 2 of the License, or (at your option)   #
# any later version.                                                          #
#                                                                             #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       #
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   #
# more details.                                                               ##                                                                             #
# You should have received a copy of the GNU General Public License along     #
# with this program; if not, write to the Free Software Foundation, Inc.,     #
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                 #
###############################################################################
# install.cgi -> Install script                                               #
###############################################################################
# DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!                         #
###############################################################################
package SL;

BEGIN { @AnyDBM_File::ISA = qw(DB_File GDBM_File NDBM_File SDBM_File) }

BEGIN {
  #############################################################################
  # Change this to the path to this script if it fails.                       #
  $SL::PATH = "."; # < < < < < < < < < < < < < < < < < < < < < < < < < < < < <#
  #############################################################################
  # DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!                       #
  #############################################################################

  $SL::EXTENSION = $0;
  $SL::EXTENSION =~s/\\/\//g;
  $SL::EXTENSION =~s/^.*\.(\w+)$/$1/g;

  foreach my $path ( $ENV{'SCRIPT_FILENAME'}, $ENV{'PATH_TRANSLATED'}, $0 ) {
    $path =~s/\\/\//g;
    $path =~s/^(.*)\/[^\/]+$/$1/g;
    if (-e $path."/install.".$SL::EXTENSION) {
      $SL::PATH = $path;
      last;
    }
  }

  unshift (@INC, "$SL::PATH");
}

eval { require 5.005; } || &CGIError("Can't load Perl version 5.005 or higher. $@", "");

use CGI;
use Cwd;
use File::Path;

use strict;

###############################################################################
# Main script: #
################

$| = 1;

eval { require Archive::Tar; } || &CGIError("Can't require Archive::Tar module. $@. Please check that it is uploaded into this directory.", "");

$SL::CGI = CGI->new();

foreach my $keyword ($SL::CGI->param()) {
  $SL::QUERY{ $keyword } = $SL::CGI->param( $keyword );
}

print "Content-Type: text/html\n\n";
$SL::HTML_HEADER = 1;

eval { &Main; } || &CGIError("Couldn't execute your request. $@.", "");
exit;

###############################################################################
# Main subroutine
sub Main {
  if ($SL::QUERY{'action'} eq "DoInstall") {
    &DoInstall() and return 1;
  } elsif ($SL::QUERY{'action'} eq "CreateTables") {
    &CreateTables() and return 1;
  } else {
    &Install() and return 1;
  }
}

###############################################################################
# Install subroutine
sub Install {
  my %in = (ERROR => "", @_);

  my %FORM;
  
  $FORM{'PATH'}         = $SL::QUERY{'FORM_PATH'} || $SL::PATH;
  $FORM{'PUBLIC_PATH'}  = $SL::QUERY{'FORM_PUBLIC_PATH'} || $FORM{'PATH'};

  $FORM{'FORM_SKIP_TARS_CHECKED'} = "checked" if ($SL::QUERY{'FORM_SKIP_TARS'});

  my $http = "http://";
     $http = "https://" if ($ENV{'CHARSET_HTTP_METHOD'} eq "https://");
  $FORM{'URL'} = $http.$ENV{'HTTP_HOST'}.$ENV{'SCRIPT_NAME'};
  $FORM{'URL'} =~ s/\/install\.$SL::EXTENSION$//;
  $FORM{'URL'} ||= $SL::QUERY{'FORM_URL'};
  $FORM{'PUBLIC_URL'} = $SL::QUERY{'FORM_PUBLIC_URL'} || $FORM{'URL'};
  
  $FORM{'DB_TYPE'}      = $SL::QUERY{'FORM_DB_TYPE'} || "dbm";
  $FORM{'SQL_SERVER'}   = $SL::QUERY{'FORM_SQL_SERVER'} || ($FORM{'DB_TYPE'} eq "oracle" ? "/dev/null" : "localhost");
  $FORM{'SQL_PORT'}     = $SL::QUERY{'FORM_SQL_PORT'} || ($FORM{'DB_TYPE'} eq "oracle" ? "/var/opt/oracle" : "3306");
  $FORM{'SQL_DB_NAME'}  = $SL::QUERY{'FORM_SQL_DB_NAME'} || "superlinks";
  $FORM{'SQL_USERNAME'} = $SL::QUERY{'FORM_SQL_USERNAME'};
  $FORM{'SQL_PASSWORD'} = $SL::QUERY{'FORM_SQL_PASSWORD'};
  $FORM{'SQL_PREFIX'}   = $SL::QUERY{'FORM_SQL_PREFIX'} || "SL_";

  $FORM{'DB_TYPE_'.$FORM{'DB_TYPE'}.'_CHECKED'} = "checked";

  foreach my $path ("/usr/sbin/sendmail", "/usr/lib/sendmail", "/usr/bin/sendmail", "/var/qmail/bin/qmail-inject") {
    $FORM{'SENDMAIL'} = $path if (-e $path);
  }
  $FORM{'SENDMAIL'} = $SL::QUERY{'FORM_SENDMAIL'} || $FORM{'SENDMAIL'};

  $FORM{'MAIL_TYPE_'.($SL::QUERY{'FORM_MAIL_TYPE'} || ($FORM{'SENDMAIL'} ? "SENDMAIL" : "SMTP")).'_CHECKED'} = "checked";

  $FORM{'SMTP_SERVER'}      = $SL::QUERY{'FORM_SMTP_SERVER'} || "localhost";
  $FORM{'EMAIL'}            = $SL::QUERY{'FORM_EMAIL'} || $ENV{'SERVER_ADMIN'};
  
  $FORM{'LOCALTIME_DST'}    = $SL::QUERY{'FORM_LOCALTIME_DST'};
  
  $FORM{'LOCALTIME_OFFSET_'.($SL::QUERY{'FORM_LOCALTIME_OFFSET'} || "0").'_SELECTED'} = "selected";
  $FORM{'DATE_FORMAT_'.($SL::QUERY{'FORM_DATE_FORMAT'} || "US").'_CHECKED'} = "checked";
  $FORM{'TIME_FORMAT_'.($SL::QUERY{'FORM_TIME_FORMAT'} || "12").'_CHECKED'} = "checked";
  
  $FORM{'ADMIN_USERNAME'}   = $SL::QUERY{'FORM_ADMIN_USERNAME'};
  $FORM{'ADMIN_PASSWORD'}   = $SL::QUERY{'FORM_ADMIN_PASSWORD'};
  $FORM{'ADMIN_NAME'}       = $SL::QUERY{'FORM_ADMIN_NAME'};

  if ($in{'ERROR'}) {
    $in{'ERROR'} = qq~<br><font color="Red">There were errors:<ul>$in{'ERROR'}</ul></font>~;
  }

  print <<HTML;
<html>

<head>
<meta name="GENERATOR" content="SuperLinks, www.plasmapulse.com">
<title>SuperLinks Installation</title>
<style>
  <!--
/* Body Properties */
body {
  padding-left    : 3px;
  padding-right   : 3px;
  padding-bottom  : 3px;
  padding-top     : 3px;
	margin          : 3px;
  background-image: url();
  background-color: #ffffff;
  color           : #000000;
}


/* Font Properties */
font       { font-size: 13px; font-family: Verdana, sans-serif; }
tr         { font-size: 13px; font-family: Verdana, sans-serif; }
font.error { color: Red; }

/* Link Properties */
a         { color: #007ee2; text-decoration: none; }
a:link    { color: #007ee2; }
a:visited { color: #007ee2; }
a:hover   { color: #ff6600; text-decoration: underline; }
a:active  { color: #ff6600; text-decoration: underline; }

/* Main Table Properties */
table.main         { width: 100%; }
table.main-border  { background-color: #82bde9; }
tr.main-background { background-color: #ffffff; }
table.row-border   { background-color: #c6def6; }

/* Title Properties */
tr.title   { background-color: #ecf6ff; }
font.title { font-size: 11px; color: #000000; }

/* Menu Properties */
tr.menu        { background-color: #c6def6; }
font.menu      { font-size: 11px; color: #000000; }

/* "Powered by" Notice Properties */
font.powered { font-size: 10px; }

/* Main Header Properties */
tr.header   { background-image: url([%system.PUBLIC_URL%]/Images/headerbg.gif); background-color: #3b8be1; }
font.header { font-weight: bold; font-size: 13px; color: #ffffff; }

/* Main Dialog Properties */
tr.body { background-color: #ffffff; }

/* Inner Table Properties */
table.table-border { background-color: #a2c8df; }
table.table        { background-color: #ecf6ff; }

/* Inner Header Properties */
tr.table-header   { background-color: #ecf6ff; }
font.table-header { font-weight: bold; font-size: 11px; color: #000000; }

/* Row Properties */
tr.table-row   { background-color: #ffffff; }
font.table-row { font-size: 11px; color: #000000; }

/* Footer Properties */
tr.table-footer   { background-color: #ecf6ff; }
font.table-footer { font-size: 11px; color: #000000; }

/* Bottom Bar Properties */
tr.bottombar { height: 18px; background-color: #ecf6ff; }

/* Form Properties */
font.form-required { font-size: 11px; color: Red; font-weight: bold; }
font.form-subject  { font-size: 11px; font-weight: bold; color: #000000; }
font.form-field    { font-size: 11px; color: #000000; }
font.form-label    { font-size: 11px; color: #000000; }

input, select, textarea { font-family: Verdana, sans-serif; background-color: ; font-size: 11px; color: #000000; }
input.form-textbox, textarea.form-textarea, select.form-selectbox { width: 100%; }

/* Divider Properties */
td.table-divider1 { background-color: #82bde9; }
td.table-divider2 { background-color: #c6def6; }
  //-->
</style>
</head>

<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

<table border="0" cellspacing="0" cellpadding="10" height="100%" class="main">
  <tr height="1">
    <td>

      <table border="0" cellpadding="1" cellspacing="1" width="100%" class="main-border">
        <form method="POST" action="$FORM{'URL'}/install.$SL::EXTENSION">
        <tr class="main-background">
          <td>
            <table border="0" cellpadding="1" cellspacing="0" width="100%">
              <tr>
                <td>
                  <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">
                    <tr class="header">
                      <td>
                        <table border="0" cellspacing="0" cellpadding="1" width="100%">
                          <tr>
                            <td width="2" nowrap></td>
                            <td width="100%"><font class="header">SuperLinks Installation</font></td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
              <tr>
                <td>
                  <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">
                    <tr class="body">
                      <td>
                        <table border="0" cellspacing="1" cellpadding="0" width="100%" class="table-border">
                          <tr>
                            <td>
                              <table border="0" cellspacing="1" cellpadding="6" width="100%" class="table">
                                <tr class="table-header">
                                  <td colspan="2"><font class="table-header">Paths</font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="100%" colspan="2"><font class="table-row">Please fill in the required (<font class="form-required">*</font>) fields:<br>$in{'ERROR'}</font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Path <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_PATH" value="$FORM{'PATH'}" class="form-textbox"><br>
                                    <font class="form-label"><small>Full UNIX-style path to the directory <i>containing</i> the install.cgi script.</small></font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Public Path <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_PUBLIC_PATH" value="$FORM{'PUBLIC_PATH'}" class="form-textbox"><br>
                                    <font class="form-label"><small>Full UNIX-style path to the directory <i>containing</i> the Public directory. Do not include /Public at the end.</small></font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap></td>
                                  <td width="100%"><font class="form-label"><input type="checkbox" name="FORM_SKIP_TARS" value="1" $FORM{'FORM_SKIP_TARS_CHECKED'}> Skip unpacking Private.tar and Public.tar files<br>
                                    <small>Only check this box if you've already unpacked the Private.tar and Public.tar files yourself (expert users only).</small></td>
                                </tr>
                                <tr class="table-header">
                                  <td colspan="2"><font class="table-header">URLs</font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">URL <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_URL" value="$FORM{'URL'}" class="form-textbox"><br>
                                    <font class="form-label"><small>Full URL to the directory <i>containing</i> the install.cgi script.</small></font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Public URL <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_PUBLIC_URL" value="$FORM{'PUBLIC_URL'}" class="form-textbox"><br>
                                    <font class="form-label"><small>Full URL to the directory <i>containing</i> the Public directory. Do not include /Public at the end.</small></font></td>
                                </tr>
                                <tr class="table-header">
                                  <td colspan="2"><font class="table-header">Database Engine</font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Database Type <font class="form-required">*</font></font></td>
                                  <td width="100%"><font class="form-label">
                                    <input type="radio" name="FORM_DB_TYPE" value="dbm" $FORM{'DB_TYPE_dbm_CHECKED'} onClick="form.action.value='Install';form.submit();"> DBM (DB, GDBM, NDBM or SDBM)<br>
                                    <input type="radio" name="FORM_DB_TYPE" value="mysql" $FORM{'DB_TYPE_mysql_CHECKED'} onClick="form.action.value='Install';form.submit();"> MySQL (requires that <i>DBI</i> and <i>DBD::MySQL</i> be installed)<br>
                                    <input type="radio" name="FORM_DB_TYPE" value="mssql" $FORM{'DB_TYPE_mssql_CHECKED'} onClick="form.action.value='Install';form.submit();"> Microsoft SQL Server (requires that <i>Win32::ODBC</i> be installed)<br>
                                    <input type="radio" name="FORM_DB_TYPE" value="oracle" $FORM{'DB_TYPE_oracle_CHECKED'} onClick="form.action.value='Install';form.submit();"> Oracle (requires that <i>DBI</i> and <i>DBD::Oracle</i> be installed)
                                    </font></td>
                                </tr>
HTML

  if ($FORM{'DB_TYPE'} eq "mysql") {
    print <<HTML;
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">SQL Server <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_SQL_SERVER" value="$FORM{'SQL_SERVER'}" class="form-textbox"></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">SQL Port <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_SQL_PORT" value="$FORM{'SQL_PORT'}" class="form-textbox"></td>
                                </tr>
HTML

  } elsif ($FORM{'DB_TYPE'} eq "oracle") {
    print <<HTML;
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Oracle Home Path (ORACLE_HOME) <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_SQL_SERVER" value="$FORM{'SQL_SERVER'}" class="form-textbox"></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">TNS Admin Path (TNS_ADMIN) <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_SQL_PORT" value="$FORM{'SQL_PORT'}" class="form-textbox"></td>
                                </tr>
HTML

  }

  unless ($FORM{'DB_TYPE'} eq "dbm") {
    print <<HTML;
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">SQL Database Name <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_SQL_DB_NAME" value="$FORM{'SQL_DB_NAME'}" class="form-textbox"></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">SQL Username <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_SQL_USERNAME" value="$FORM{'SQL_USERNAME'}" class="form-textbox"></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">SQL Password <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_SQL_PASSWORD" value="$FORM{'SQL_PASSWORD'}" class="form-textbox"></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">SQL Table Prefix <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_SQL_PREFIX" value="$FORM{'SQL_PREFIX'}" class="form-textbox"></td>
                                </tr>
HTML

  }
  
  print <<HTML;
                                <tr class="table-header">
                                  <td colspan="2"><font class="table-header">Mail System</font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Mail System <font class="form-required">*</font></font></td>
                                  <td width="100%"><font class="form-label">
                                    <input type="radio" name="FORM_MAIL_TYPE" value="SENDMAIL" $FORM{'MAIL_TYPE_SENDMAIL_CHECKED'}> Sendmail<br>
                                    <input type="radio" name="FORM_MAIL_TYPE" value="SMTP" $FORM{'MAIL_TYPE_SMTP_CHECKED'}> SMTP
                                    </font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Sendmail Path</font></td>
                                  <td width="100%"><input type="text" name="FORM_SENDMAIL" value="$FORM{'SENDMAIL'}" class="form-textbox"></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">SMTP Server</font></td>
                                  <td width="100%"><input type="text" name="FORM_SMTP_SERVER" value="$FORM{'SMTP_SERVER'}" class="form-textbox"></td>
                                </tr>
                                <tr class="table-header">
                                  <td colspan="2"><font class="table-header">Date &amp; Time Options</font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Local Timezone <font class="form-required">*</font></font></td>
                                  <td width="100%"><select name="FORM_LOCALTIME_OFFSET" class="form-selectbox">
                                    <option value="-12" $FORM{'LOCALTIME_OFFSET_-12_SELECTED'}>(GMT -12:00) International Date Line West</option>
                                    <option value="-11" $FORM{'LOCALTIME_OFFSET_-11_SELECTED'}>(GMT -11:00) Midway Island, Samoa</option>
                                    <option value="-10" $FORM{'LOCALTIME_OFFSET_-10_SELECTED'}>(GMT -10:00) Hawaii</option>
                                    <option value="-9" $FORM{'LOCALTIME_OFFSET_-9_SELECTED'}>(GMT -09:00) Alaska</option>
                                    <option value="-8" $FORM{'LOCALTIME_OFFSET_-8_SELECTED'}>(GMT -08:00) Pacific Time (US & Canada); Tijuana</option>
                                    <option value="-7" $FORM{'LOCALTIME_OFFSET_-7_SELECTED'}>(GMT -07:00) Mountain Time (US & Canada); Arizona, Chihuahua, La Paz, Mazatlan</option>
                                    <option value="-6" $FORM{'LOCALTIME_OFFSET_-6_SELECTED'}>(GMT -06:00) Central Time (US & Canada); Central America, Guadalajara, Mexico City, Monterrey, Saskatchewan</option>
                                    <option value="-5" $FORM{'LOCALTIME_OFFSET_-5_SELECTED'}>(GMT -05:00) Eastern Time (US & Canada); Bogota, Lima, Quito, Indiana (East)</option>
                                    <option value="-4" $FORM{'LOCALTIME_OFFSET_-4_SELECTED'}>(GMT -04:00) Atlantic Time (Canada); Caracas, La Paz, Santiago</option>
                                    <option value="-3.5" $FORM{'LOCALTIME_OFFSET_-3.5_SELECTED'}>(GMT -03:30) Newfoundland</option>
                                    <option value="-3" $FORM{'LOCALTIME_OFFSET_-3_SELECTED'}>(GMT -03:00) Brasilia, Buenos Aires, Georgetown, Greenland</option>
                                    <option value="-2" $FORM{'LOCALTIME_OFFSET_-2_SELECTED'}>(GMT -02:00) Mid-Atlantic</option>
                                    <option value="-1" $FORM{'LOCALTIME_OFFSET_-1_SELECTED'}>(GMT -01:00) Azores, Cape Verde Is.</option>
                                    <option value="0" $FORM{'LOCALTIME_OFFSET_0_SELECTED'}>(GMT) Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London; Casablanca, Monrovia</option>
                                    <option value="1" $FORM{'LOCALTIME_OFFSET_1_SELECTED'}>(GMT +01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna, Belgrade, Bratislava, Budapest, Ljubljana, Prague, Brussels, Copenhagen, Madrid, Paris, Sarajevo, Skopje, Warsaw, Zagreb, West Central Africa</option>
                                    <option value="2" $FORM{'LOCALTIME_OFFSET_2_SELECTED'}>(GMT +02:00) Athens, Istanbul, Minsk, Bucharest, Cairo, Harare, Pretoria, Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius, Jerusalem</option>
                                    <option value="3" $FORM{'LOCALTIME_OFFSET_3_SELECTED'}>(GMT +03:00) Baghdad, Kuwait, Riyadh, Moscow, St. Petersburg, Volgograd, Nairobi</option>
                                    <option value="3.5" $FORM{'LOCALTIME_OFFSET_3.5_SELECTED'}>(GMT +03:30) Tehran</option>
                                    <option value="4" $FORM{'LOCALTIME_OFFSET_4_SELECTED'}>(GMT +04:00) Abu Dhabi, Muscat, Baku, Tbilsi, Yerevan</option>
                                    <option value="4.5" $FORM{'LOCALTIME_OFFSET_4.5_SELECTED'}>(GMT +04:30) Kabul</option>
                                    <option value="5" $FORM{'LOCALTIME_OFFSET_5_SELECTED'}>(GMT +05:00) Ekaterinburg, Islamabad, Karachi, Tashkent</option>
                                    <option value="5.5" $FORM{'LOCALTIME_OFFSET_5.5_SELECTED'}>(GMT +05:30) Chennai, Kolkata, Mumbai, New Delhi</option>
                                    <option value="5.75" $FORM{'LOCALTIME_OFFSET_5.75_SELECTED'}>(GMT +05:45) Kathmandu</option>
                                    <option value="6" $FORM{'LOCALTIME_OFFSET_6_SELECTED'}>(GMT +06:00) Almaty, Novosibirsk, Astana, Dhaka, Sri Jayawarenepura</option>
                                    <option value="6.5" $FORM{'LOCALTIME_OFFSET_6.5_SELECTED'}>(GMT +06:30) Rangoon</option>
                                    <option value="7" $FORM{'LOCALTIME_OFFSET_7_SELECTED'}>(GMT +07:00) Bankok, Hanoi, Jakarta, Krasnoyarsk</option>
                                    <option value="8" $FORM{'LOCALTIME_OFFSET_8_SELECTED'}>(GMT +08:00) Beijing, Chongqing, Hong Kong, Urumqi, Irkutsk, Ulaan Bataar, Kuala Lumpur, Singapore, Perth, Taipei</option>
                                    <option value="9" $FORM{'LOCALTIME_OFFSET_9_SELECTED'}>(GMT +09:00) Osaka, Sapporo, Tokyo, Seoul, Yakutsk</option>
                                    <option value="9.5" $FORM{'LOCALTIME_OFFSET_9.5_SELECTED'}>(GMT +09:30) Adelaide, Darwin</option>
                                    <option value="10" $FORM{'LOCALTIME_OFFSET_10_SELECTED'}>(GMT +10:00) Brisbane, Canberra, Melbourne, Sydney, Guam, Port Moresby, Hobart, Vladivostok</option>
                                    <option value="11" $FORM{'LOCALTIME_OFFSET_11_SELECTED'}>(GMT +11:00) Magadan, Soloman Is., New Caledonia</option>
                                    <option value="12" $FORM{'LOCALTIME_OFFSET_12_SELECTED'}>(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka, Marshall Is.</option>
                                    <option value="13" $FORM{'LOCALTIME_OFFSET_13_SELECTED'}>(GMT +13:00) Nuku'alofa</option>
                                    </select>
                                  </td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap></td>
                                  <td width="100%"><font class="form-label"><input type="checkbox" name="FORM_LOCALTIME_DST" value="1"> Automatically adjust time for daylight saving changes?</font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Date Format <font class="form-required">*</font></font></td>
                                  <td width="100%"><font class="form-label">
                                    <input type="radio" name="FORM_DATE_FORMAT" value="US" $FORM{'DATE_FORMAT_US_CHECKED'}> US Format (MM-DD-YYYY)<br>
                                    <input type="radio" name="FORM_DATE_FORMAT" value="USE" $FORM{'DATE_FORMAT_USE_CHECKED'}> Extended US Format (Month DD, YYYY)<br>
                                    <input type="radio" name="FORM_DATE_FORMAT" value="EU" $FORM{'DATE_FORMAT_EU_CHECKED'}> EU Format (DD-MM-YYYY)<br>
                                    <input type="radio" name="FORM_DATE_FORMAT" value="EUE" $FORM{'DATE_FORMAT_EUE_CHECKED'}> Extended EU Format (DD Month, YYYY)
                                    </font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Time Format <font class="form-required">*</font></font></td>
                                  <td width="100%"><font class="form-label">
                                    <input type="radio" name="FORM_TIME_FORMAT" value="24" $FORM{'TIME_FORMAT_24_CHECKED'}> 24 Hour Time Format<br>
                                    <input type="radio" name="FORM_TIME_FORMAT" value="12" $FORM{'TIME_FORMAT_12_CHECKED'}> AM/PM 12 Hour Time Format
                                    </font></td>
                                </tr>
                                <tr class="table-header">
                                  <td colspan="2"><font class="table-header">Misc. Options</font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Contact Email Address <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_EMAIL" value="$FORM{'EMAIL'}" class="form-textbox"></td>
                                </tr>
                                <tr class="table-header">
                                  <td colspan="2"><font class="table-header">Administrator Account</font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Chosen Username <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_ADMIN_USERNAME" value="$FORM{'ADMIN_USERNAME'}" class="form-textbox"></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Chosen Password <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_ADMIN_PASSWORD" value="$FORM{'ADMIN_PASSWORD'}" class="form-textbox"></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap><font class="form-subject">Chosen Name <font class="form-required">*</font></font></td>
                                  <td width="100%"><input type="text" name="FORM_ADMIN_NAME" value="$FORM{'ADMIN_NAME'}" class="form-textbox"></td>
                                </tr>
                                <tr class="table-row">
                                  <td colspan="2">
                                    <table border="0" cellspacing="0" cellpadding="0" width="100%">
                                      <tr><td height="2" class="table-divider1"></td></tr>
                                      <tr><td height="1" class="table-divider2"></td></tr>
                                    </table>
                                  </td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap></td>
                                  <td width="100%"><input type="submit" value="Next >">&nbsp;<input type="reset" value="Cancel"></td>
                                </tr>
                              </table>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
              <tr>
                <td>
                  <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">
                    <tr class="bottombar">
                      <td><font class="bottombar"></font></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <input type="hidden" name="action" value="DoInstall">
        </form>
      </table>

    </td>
  </tr>
  <tr height="100%">
    <td align="right" valign="bottom"><font class="powered">Powered by <a href="http://www.plasmapulse.com/?sc=SuperLinks">SuperLinks</a> Standard Edition.<br>
      Copyright 2000-2003 &copy; <a href="http://www.plasmapulse.com">PlasmaPulse Solutions</a>. All rights reserved.</font></td>
  </tr>
</table>

</body>

</html>
HTML

  return 1;
}

###############################################################################
# DoInstall subroutine
sub DoInstall {
  my $Exit = eval {
    sub {
      print <<HTML;
                                    </ul>
                                  </td>
                                </tr>
                              </table>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
              <tr>
                <td>
                  <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">
                    <tr class="bottombar">
                      <td><font class="bottombar"></font></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        </form>
      </table>

    </td>
  </tr>
  <tr height="100%">
    <td align="right" valign="bottom"><font class="powered">Powered by <a href="http://www.plasmapulse.com/?sc=SuperLinks">SuperLinks</a> Standard Edition.<br>
      Copyright 2000-2003 &copy; <a href="http://www.plasmapulse.com">PlasmaPulse Solutions</a>. All rights reserved.</font></td>
  </tr>
</table>

</body>

</html>
HTML

      exit;
    }
  };

  my %Fields = (
    "PATH"              => "Path",
    "PUBLIC_PATH"       => "Public Path",
    "URL"               => "URL",
    "PUBLIC_URL"        => "Public URL",
    "DB_TYPE"           => "Database Type",
    "MAIL_TYPE"         => "Mail Type",
    "EMAIL"             => "Your Email Address",
    "LOCALTIME_OFFSET"  => "Server Time Offset",
    "DATE_FORMAT"       => "Date Format",
    "TIME_FORMAT"       => "Time Format",
    "ADMIN_USERNAME"    => "Admin Username",
    "ADMIN_PASSWORD"    => "Admin Password",
    "ADMIN_NAME"        => "Admin Name"
  );

  my (%FORM, $Error);
  foreach my $key (keys %Fields) {
    if ($SL::QUERY{'FORM_'.$key} eq "") {
      $Error .= qq~<li>You didn't fill in the "$Fields{$key}" field.\n~;
    } else {
      $FORM{$key} = $SL::QUERY{'FORM_'.$key};
    }
  }

  $FORM{'LOCALTIME_DST'} = $SL::QUERY{'FORM_LOCALTIME_DST'};
  $FORM{'SKIP_TARS'}     = $SL::QUERY{'FORM_SKIP_TARS'};
  
  if ($FORM{'DB_TYPE'} eq "mysql") {
    $FORM{'DB_SERVER'}    = $SL::QUERY{'FORM_SQL_SERVER'};
    $FORM{'DB_PORT'}      = $SL::QUERY{'FORM_SQL_PORT'};
    $FORM{'DB_NAME'}      = $SL::QUERY{'FORM_SQL_DB_NAME'};
    $FORM{'DB_USERNAME'}  = $SL::QUERY{'FORM_SQL_USERNAME'};
    $FORM{'DB_PASSWORD'}  = $SL::QUERY{'FORM_SQL_PASSWORD'};
    $FORM{'DB_PREFIX'}    = $SL::QUERY{'FORM_SQL_PREFIX'};
    
    $Error .= qq~<li>You didn't fill in the "SQL Server" field.\n~ unless ($FORM{'DB_SERVER'});
    $Error .= qq~<li>You didn't fill in the "SQL Port" field.\n~ unless ($FORM{'DB_PORT'});
    $Error .= qq~<li>You didn't fill in the "SQL Database Name" field.\n~ unless ($FORM{'DB_NAME'});
    $Error .= qq~<li>You didn't fill in the "SQL Username" field.\n~ unless ($FORM{'DB_USERNAME'});
    $Error .= qq~<li>You didn't fill in the "SQL Password" field.\n~ unless ($FORM{'DB_PASSWORD'});
    $Error .= qq~<li>You didn't fill in the "SQL Table Prefix" field.\n~ unless ($FORM{'DB_PREFIX'});
  } elsif ($FORM{'DB_TYPE'} eq "mssql") {
    $FORM{'DB_NAME'}      = $SL::QUERY{'FORM_SQL_DB_NAME'};
    $FORM{'DB_USERNAME'}  = $SL::QUERY{'FORM_SQL_USERNAME'};
    $FORM{'DB_PASSWORD'}  = $SL::QUERY{'FORM_SQL_PASSWORD'};
    $FORM{'DB_PREFIX'}    = $SL::QUERY{'FORM_SQL_PREFIX'};

    $Error .= qq~<li>You didn't fill in the "SQL Database Name" field.\n~ unless ($FORM{'DB_NAME'});
    $Error .= qq~<li>You didn't fill in the "SQL Username" field.\n~ unless ($FORM{'DB_USERNAME'});
    $Error .= qq~<li>You didn't fill in the "SQL Password" field.\n~ unless ($FORM{'DB_PASSWORD'});
    $Error .= qq~<li>You didn't fill in the "SQL Table Prefix" field.\n~ unless ($FORM{'DB_PREFIX'});
  } elsif ($FORM{'DB_TYPE'} eq "oracle") {
    $FORM{'DB_SERVER'}    = $SL::QUERY{'FORM_SQL_SERVER'};
    $FORM{'DB_PORT'}      = $SL::QUERY{'FORM_SQL_PORT'};
    $FORM{'DB_NAME'}      = $SL::QUERY{'FORM_SQL_DB_NAME'};
    $FORM{'DB_USERNAME'}  = $SL::QUERY{'FORM_SQL_USERNAME'};
    $FORM{'DB_PASSWORD'}  = $SL::QUERY{'FORM_SQL_PASSWORD'};
    $FORM{'DB_PREFIX'}    = $SL::QUERY{'FORM_SQL_PREFIX'};
    
    $Error .= qq~<li>You didn't fill in the "Oracle Home Path (ORACLE_HOME)" field.\n~ unless ($FORM{'DB_SERVER'});
    $Error .= qq~<li>You didn't fill in the "TNS Admin Path (TNS_ADMIN)" field.\n~ unless ($FORM{'DB_PORT'});
    $Error .= qq~<li>You didn't fill in the "SQL Database Name" field.\n~ unless ($FORM{'DB_NAME'});
    $Error .= qq~<li>You didn't fill in the "SQL Username" field.\n~ unless ($FORM{'DB_USERNAME'});
    $Error .= qq~<li>You didn't fill in the "SQL Password" field.\n~ unless ($FORM{'DB_PASSWORD'});
    $Error .= qq~<li>You didn't fill in the "SQL Table Prefix" field.\n~ unless ($FORM{'DB_PREFIX'});
  }

  if ($FORM{'MAIL_TYPE'} eq "SENDMAIL") {
    $FORM{'SENDMAIL'} = $SL::QUERY{'FORM_SENDMAIL'};
    $Error .= qq~<li>You didn't fill in the "Sendmail Path" field.\n~ unless ($FORM{'SENDMAIL'});
  } else {
    $FORM{'SMTP_SERVER'} = $SL::QUERY{'FORM_SMTP_SERVER'};
    $Error .= qq~<li>You didn't fill in the "SMTP Server" field.\n~ unless ($FORM{'SMTP_SERVER'});
  }
  
  &Install(ERROR => $Error) and return 1 if ($Error);

  print <<HTML;
<html>

<head>
<meta name="GENERATOR" content="SuperLinks, www.plasmapulse.com">
<title>SuperLinks Installation</title>
<style>
  <!--
/* Body Properties */
body {
  padding-left    : 3px;
  padding-right   : 3px;
  padding-bottom  : 3px;
  padding-top     : 3px;
	margin          : 3px;
  background-image: url();
  background-color: #ffffff;
  color           : #000000;
}


/* Font Properties */
font       { font-size: 13px; font-family: Verdana, sans-serif; }
tr         { font-size: 13px; font-family: Verdana, sans-serif; }
font.error { color: Red; }

/* Link Properties */
a         { color: #007ee2; text-decoration: none; }
a:link    { color: #007ee2; }
a:visited { color: #007ee2; }
a:hover   { color: #ff6600; text-decoration: underline; }
a:active  { color: #ff6600; text-decoration: underline; }

/* Main Table Properties */
table.main         { width: 100%; }
table.main-border  { background-color: #82bde9; }
tr.main-background { background-color: #ffffff; }
table.row-border   { background-color: #c6def6; }

/* Title Properties */
tr.title   { background-color: #ecf6ff; }
font.title { font-size: 11px; color: #000000; }

/* Menu Properties */
tr.menu        { background-color: #c6def6; }
font.menu      { font-size: 11px; color: #000000; }

/* "Powered by" Notice Properties */
font.powered { font-size: 10px; }

/* Main Header Properties */
tr.header   { background-image: url([%system.PUBLIC_URL%]/Images/headerbg.gif); background-color: #3b8be1; }
font.header { font-weight: bold; font-size: 13px; color: #ffffff; }

/* Main Dialog Properties */
tr.body { background-color: #ffffff; }

/* Inner Table Properties */
table.table-border { background-color: #a2c8df; }
table.table        { background-color: #ecf6ff; }

/* Inner Header Properties */
tr.table-header   { background-color: #ecf6ff; }
font.table-header { font-weight: bold; font-size: 11px; color: #000000; }

/* Row Properties */
tr.table-row   { background-color: #ffffff; }
font.table-row { font-size: 11px; color: #000000; }

/* Footer Properties */
tr.table-footer   { background-color: #ecf6ff; }
font.table-footer { font-size: 11px; color: #000000; }

/* Bottom Bar Properties */
tr.bottombar { height: 18px; background-color: #ecf6ff; }

/* Form Properties */
font.form-required { font-size: 11px; color: Red; font-weight: bold; }
font.form-subject  { font-size: 11px; font-weight: bold; color: #000000; }
font.form-field    { font-size: 11px; color: #000000; }
font.form-label    { font-size: 11px; color: #000000; }

input, select, textarea { font-family: Verdana, sans-serif; background-color: ; font-size: 11px; color: #000000; }
input.form-textbox, textarea.form-textarea, select.form-selectbox { width: 100%; }

/* Divider Properties */
td.table-divider1 { background-color: #82bde9; }
td.table-divider2 { background-color: #c6def6; }
  //-->
</style>
</head>

<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

<table border="0" cellspacing="0" cellpadding="10" height="100%" class="main">
  <tr height="1">
    <td>

      <table border="0" cellpadding="1" cellspacing="1" width="100%" class="main-border">
        <form method="POST" action="$FORM{'URL'}/install.$SL::EXTENSION">
        <tr class="main-background">
          <td>
            <table border="0" cellpadding="1" cellspacing="0" width="100%">
              <tr>
                <td>
                  <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">
                    <tr class="header">
                      <td>
                        <table border="0" cellspacing="0" cellpadding="1" width="100%">
                          <tr>
                            <td width="2" nowrap></td>
                            <td width="100%"><font class="header">SuperLinks Installation Process</font></td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
              <tr>
                <td>
                  <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">
                    <tr class="body">
                      <td>
                        <table border="0" cellspacing="1" cellpadding="0" width="100%" class="table-border">
                          <tr>
                            <td>
                              <table border="0" cellspacing="1" cellpadding="6" width="100%" class="table">
                                <tr class="table-header">
                                  <td colspan="2"><font class="table-header">Paths</font></td>
                                </tr>
                                <tr class="table-row">
                                  <td width="100%" colspan="2">
                                    <ul>
HTML

  print qq~<li>Checking Path... ~;
  if (-e $FORM{'PATH'}) {
    print qq~<font color="Green">Path found.</font>\n~;
  } else {
    print qq~<font color="Red">Path not found. Please check it and try again.</font>\n~ and &$Exit;
  }

  print qq~<li>Checking Public Path... ~;
  if (-e $FORM{'PUBLIC_PATH'}) {
    print qq~<font color="Green">Path found.</font>\n~;
  } else {
    print qq~<font color="Red">Path not found. Please check it and try again.</font>\n~ and &$Exit;
  }

  print qq~<li>Checking Private directory... ~;
  if (-e "$FORM{'PATH'}/Private") {
    if (open(TEST, ">$FORM{'PATH'}/Private/test.txt")) {
      print qq~<font color="Green">Seems OK.</font>\n~;
    } else {
      print qq~<font color="Red">Couldn't write to directory. Check that the permissions on the Private directory allow writing (i.e. CHMOD it to 777).</font>\n~ and &$Exit;
    }
  } else {
    if (mkdir("$FORM{'PATH'}/Private", 0777)) {
      chmod(0777, "$FORM{'PATH'}/Private");
      print qq~<font color="Green">Directory created OK.</font>\n~;
    } else {
      print qq~<font color="Red">Couldn't find existing directory and couldn't create a new one. Create a Private directory and CHMOD it to 777 if necessary.</font>\n~ and &$Exit;
    }
  }

  print qq~<li>Checking Public directory... ~;
  if (-e "$FORM{'PUBLIC_PATH'}/Public") {
    if (open(TEST, ">$FORM{'PUBLIC_PATH'}/Public/test.txt")) {
      print qq~<font color="Green">Seems OK.</font>\n~;
    } else {
      print qq~<font color="Red">Couldn't write to directory. Check that the permissions on the Public directory allow writing (i.e. CHMOD it to 777).</font>\n~ and &$Exit;
    }
  } else {
    if (mkdir("$FORM{'PUBLIC_PATH'}/Public", 0777)) {
      chmod(0777, "$FORM{'PUBLIC_PATH'}/Public");
      print qq~<font color="Green">Directory created OK.</font>\n~;
    } else {
      print qq~<font color="Red">Couldn't find existing directory and couldn't create a new one. Create a Public directory and CHMOD it to 777 if necessary.</font>\n~ and &$Exit;
    }
  }

  print qq~<li>Checking URL... ~;
  $FORM{'URL'} =~ s/\\/\//g;
  $FORM{'URL'} =~ s/\/$//g;
  if ($FORM{'URL'} =~/^http(s)?:\/\//i) {
    print qq~<font color="Green">Seems OK.</font>\n~;
  } else {
    print qq~<font color="Red">URL is incorrect. Please check it and try again.</font>\n~ and &$Exit;
  }

  print qq~<li>Checking Public URL... ~;
  $FORM{'PUBLIC_URL'} =~ s/\\/\//g;
  $FORM{'PUBLIC_URL'} =~ s/\/$//g;
  if ($FORM{'PUBLIC_URL'} =~/^http(s)?:\/\//i) {
    print qq~<font color="Green">Seems OK.</font>\n~;
  } else {
    print qq~<font color="Red">URL is incorrect. Please check it and try again.</font>\n~ and &$Exit;
  }

  unless ($FORM{'SKIP_TARS'}) {
    print qq~<li>Extracting Private.tar...\n~;
    print qq~<ul>\n~;
  
    print qq~<li>Checking Private.tar... ~;
    if (-e "$FORM{'PATH'}/Private.tar") {
      open(FILE, "$FORM{'PATH'}/Private.tar") || (print qq~<font color="Red">Error opening file for reading. $!.</font>\n~ and &$Exit);
      binmode(FILE);
      my $privatecrc = do {
        local $/;
        unpack("%32C*", <FILE>) % 65535;
      };
      close(FILE);
    
      if ($privatecrc != 20191) {
        print qq~<font color="Red">A CRC check on the file failed. Please check that it is the original file and that you uploaded it in BINARY mode.</font>\n~ and &$Exit;
      }
    } else {
      print qq~<font color="Red">Can't find Private.tar file. Please check that the file exists in $FORM{'PATH'}.</font>\n~ and &$Exit;
    }
    print qq~<font color="Green">Seems OK.</font>\n~;

    print qq~<li>Unpacking Private.tar into $FORM{'PATH'}... ~;
    my $Cwd = cwd() || $SL::PATH;

    my $Tar = Archive::Tar->new();
    unless ($Tar->read("$FORM{'PATH'}/Private.tar", 0)) {
      print qq~<font color="Red">Error reading Private.tar file. $!.</font>\n~ and &$Exit;
    }

    chdir($FORM{'PATH'});
    my @Files = $Tar->list_files();
    $Tar->extract(@Files, $FORM{'PATH'});
    chdir($Cwd);
    print qq~<font color="Green">All files should be extracted.</font>\n~;

    print qq~<li>Checking that files were extracted correctly... ~;
    my $error;
    foreach my $file (@Files) {
      unless (-e "$FORM{'PATH'}/$file") {
        $error = 1;
        last;
      }
    }
    if ($error) {
      print qq~<font color="Red">One or more files were not extracted correctly. Please check the directory permissions and try again.</font>\n~ and &$Exit;
    } else {
      print qq~<font color="Green">All extracted OK.</font>\n~;
    }

    print qq~<li>Checking for Private directory... ~;
    if (-e "$FORM{'PATH'}/Private") {
      print qq~<font color="Green">Path found.</font>\n~;
    } else {
      print qq~<font color="Red">Path not found. Please create it and CHMOD it to 777.</font>\n~ and &$Exit;
    }

    print qq~</ul>\n~;
  
    print qq~<li>Extracting Public.tar...\n~;
    print qq~<ul>\n~;

    print qq~<li>Checking Public.tar... ~;
    if (-e "$FORM{'PATH'}/Public.tar") {
      open(FILE, "$FORM{'PATH'}/Public.tar") || (print qq~<font color="Red">Error opening file for reading. $!.</font>\n~ and &$Exit);
      binmode(FILE);
      my $publiccrc = do {
        local $/;
        unpack("%32C*", <FILE>) % 65535;
      };
      close(FILE);
    
      if ($publiccrc != 2543) {
        print qq~<font color="Red">A CRC check on the file failed. Please check that it is the original file and that you uploaded it in BINARY mode.</font>\n~ and &$Exit;
      }
    } else {
      print qq~<font color="Red">Can't find Public.tar file. Please check that the file exists in $FORM{'PATH'}.</font>\n~ and &$Exit;
    }
    print qq~<font color="Green">Seems OK.</font>\n~;

    print qq~<li>Unpacking Public.tar into $FORM{'PUBLIC_PATH'}... ~;
    my $Cwd = cwd() || $SL::PATH;

    my $Tar = Archive::Tar->new();
    unless ($Tar->read("$FORM{'PATH'}/Public.tar", 0)) {
      print qq~<font color="Red">Error reading Public.tar file. $!.</font>\n~ and &$Exit;
    }

    chdir($FORM{'PUBLIC_PATH'});
    my @Files = $Tar->list_files();
    $Tar->extract(@Files, $FORM{'PUBLIC_PATH'});
    chdir($Cwd);
    print qq~<font color="Green">All files should be extracted.</font>\n~;

    print qq~<li>Checking that files were extracted correctly... ~;
    my $error;
    foreach my $file (@Files) {
      unless (-e "$FORM{'PUBLIC_PATH'}/$file") {
        $error = 1;
        last;
      }
    }
    if ($error) {
      print qq~<font color="Red">One or more files were not extracted correctly. Please check the directory permissions and try again.</font>\n~ and &$Exit;
    } else {
      print qq~<font color="Green">All extracted OK.</font>\n~;
    }

    print qq~<li>Checking for Public directory... ~;
    if (-e "$FORM{'PUBLIC_PATH'}") {
      print qq~<font color="Green">Path found.</font>\n~;
    } else {
      print qq~<font color="Red">Path not found. Please create it and CHMOD it to 777.</font>\n~ and &$Exit;
    }

    print qq~</ul>\n~;
  }

  print qq~<li>Creating extra directories... ~;
  my @Directories = (
    "$FORM{'PATH'}/Private/Database",
    "$FORM{'PATH'}/Private/Database/Temp",
    "$FORM{'PATH'}/Private/Database/Temp/Cache",
    "$FORM{'PATH'}/Private/Logs",
    "$FORM{'PATH'}/Private/Backups",
    "$FORM{'PATH'}/Private/Plugins",
    "$FORM{'PUBLIC_PATH'}/Public/Static/Category",
    "$FORM{'PUBLIC_PATH'}/Public/Static/Detail",
    "$FORM{'PUBLIC_PATH'}/Public/Upload"
  );
  foreach my $dir (@Directories) {
    if (-e $dir) {
      rmtree($dir) || (print qq~<font color="Red">Error removing existing $dir. $!.</font>\n~ and &$Exit);
    }
    mkdir($dir, 0777) || (print qq~<font color="Red">Error creating $dir. $!.</font>\n~ and &$Exit);
    chmod(0777, $dir);
  }
  print qq~<font color="Green">All directories should be created now.</font>\n~;

  print qq~<li>Writing system variable file... ~;
  my $Variables;
  eval {
    require "$FORM{'PATH'}/Private/Modules/Libraries/Variables.pm.pl";
    $Variables = Variables->new();
  } || (print qq~<font color="Red">Error requiring Variables.pm.pl library. $@.</font>\n~ and &$Exit);

  $Variables->Update(
    FILE      => "$FORM{'PATH'}/Private/Variables/System.pm.pl",
    PACKAGE   => "System",
    VARIABLE  => "SYSTEM",
    VALUES    => {
      "INSTALLED"         => "1",
      "DB_PATH"           => "$FORM{'PATH'}/Private/Database",
      "TEMP_PATH"         => "$FORM{'PATH'}/Private/Database/Temp",
      "LOGS_PATH"         => "$FORM{'PATH'}/Private/Logs",
      "BACKUP_PATH"       => "$FORM{'PATH'}/Private/Backups",
      "CACHE_PATH"        => "$FORM{'PATH'}/Private/Database/Temp/Cache",
      "PUBLIC_PATH"       => "$FORM{'PUBLIC_PATH'}/Public",
      
      "SCRIPT_URL"        => "$FORM{'URL'}/SuperLinks.$SL::EXTENSION",
      "PUBLIC_URL"        => "$FORM{'PUBLIC_URL'}/Public",
      
      "DB_TYPE"           => $FORM{'DB_TYPE'},
      
      "DB_PREFIX"         => $FORM{'DB_PREFIX'},
      "DB_HOST"           => $FORM{'DB_SERVER'},
      "DB_PORT"           => $FORM{'DB_PORT'},
      "DB_NAME"           => $FORM{'DB_NAME'},
      "DB_USERNAME"       => $FORM{'DB_USERNAME'},
      "DB_PASSWORD"       => $FORM{'DB_PASSWORD'},
      
      "MAIL_TYPE"         => $FORM{'MAIL_TYPE'},
      "SENDMAIL"          => $FORM{'SENDMAIL'},
      "SMTP_SERVER"       => $FORM{'SMTP_SERVER'},
      
      "LOCALTIME_OFFSET"  => $FORM{'LOCALTIME_OFFSET'},
      "LOCALTIME_DST"     => $FORM{'LOCALTIME_DST'}
    }
  ) || (print qq~<font color="Red">Error writing to the System.pm.pl file in $FORM{'PATH'}/Private/Variables. $Variables->{'ERROR'}. Please check that it exists and try again.</font>\n~ and &$Exit);
  print qq~<font color="Green">Complete.</font>\n~;

  print qq~<li>Writing general variable file... ~;
  $Variables->Update(
    FILE      => "$FORM{'PATH'}/Private/Variables/General.pm.pl",
    PACKAGE   => "General",
    VARIABLE  => "GENERAL",
    VALUES    => {
      "CONTACT_EMAIL"   => $FORM{'EMAIL'},
      "ADMIN_EMAIL"     => $FORM{'EMAIL'},
      "DATE_FORMAT"     => $FORM{'DATE_FORMAT'},
      "TIME_FORMAT"     => $FORM{'TIME_FORMAT'}
    }
  ) || (print qq~<font color="Red">Error writing to the General.pm.pl file in $FORM{'PATH'}/Private/Variables. $Variables->{'ERROR'}. Please check that it exists and try again.</font>\n~ and &$Exit);
  print qq~<font color="Green">Complete.</font>\n~;

  print qq~<li>Checking for recommended modules...\n~;
  print qq~<ul>\n~;
  my %Modules = (
    "Compress::Zlib"    => "You will not be able to compress backups into .tar.gz archives",
    "LWP"               => "You will not be able to use the Check Resources or Update features"
  );
  foreach my $module (keys %Modules) {
    print qq~<li>Checking $module module... ~;
    eval "use ".$module;
    if ($@) {
      print qq~<font color="Olive">Could not find $module module. $Modules{$module}.</font>\n~;
    } else {
      print qq~<font color="Green">Module found.</font>\n~;
    }
  }
  print qq~</ul>\n~;

  if ($FORM{'DB_TYPE'} eq "mysql") {
    print qq~<li>You chose to use the MySQL database engine.<br>\n~;
    print qq~<ul>\n~;
    print qq~<li>Checking DBI module... ~;
    eval "use DBI";
    if ($@) {
      print qq~<font color="Red">Could not find DBI module. Please check that DBI is available to use on your system and try again.</font>\n~ and &$Exit;
    } else {
      print qq~<font color="Green">Module found.</font>\n~;
    }

    print qq~<li>Checking the MySQL driver... ~;
    my $found = 0;
    my @drivers = DBI->available_drivers();
    foreach my $driver (@drivers) {
      $found = 1 and last if (index($driver, "mysql") != -1);
    }
    if ($found) {
      print qq~<font color="Green">Driver found.</font>\n~;
    } else {
      print qq~<font color="Red">Could not find a MySQL driver. Please check that a MySQL driver (DBD::MYSQL) is available for use on your system and try again.</font>\n~ and &$Exit;
    }

    print qq~<li>Trying to connect to the database... ~;
    $found = 0;
    my $DSN  = "DBI:mysql:$FORM{'DB_NAME'}:$FORM{'DB_SERVER'}";
       $DSN .= ":$FORM{'DB_PORT'}" if ($FORM{'DB_PORT'});
    my $DBH ||= DBI->connect($DSN, $FORM{'DB_USERNAME'}, $FORM{'DB_PASSWORD'}) || (print qq~<font color="Red">Couldn't connect to the database server ($FORM{'DB_SERVER'}) and database ($FORM{'DB_NAME'}). $DBI::errstr</font>\n~ and &$Exit);
    my $STH = $DBH->prepare("SHOW DATABASES");
       $STH->execute();
    while (my @log = $STH->fetchrow_array()) {
      $found = 1 if ($log[0] eq $FORM{'DB_NAME'});
    }
    if ($found) {
      print qq~<font color="Green">Connected OK.</font>\n~;
    } else {
      print qq~<font color="Red">Couldn't find the database ($FORM{'DB_NAME'}). Please check to see if the database has been created and check to see that the permissions on the MySQL username ($FORM{'DB_USERNAME'}) are correct.</font>\n~ and &$Exit;
    }
    $DBH->disconnect();
    
    print qq~</ul>\n~;
  } elsif ($FORM{'DB_TYPE'} eq "mssql") {
    print qq~<li>You chose to use the Microsoft SQL Server database engine.\n~;
    print qq~<ul>\n~;
    print qq~<li>Checking the Win32::ODBC module... ~;
    eval "use Win32::ODBC";
    if ($@) {
      print qq~<font color="Red">Couldn't find the Win32::ODBC module. Please check that it is installed on the server and try again.</font>\n~ and &$Exit;
    } else {
      print qq~<font color="Green">Found OK.</font>\n~;
    }
    print qq~<li>Trying to connect to the database... ~;
    my $DSN = "dsn=$FORM{'DB_NAME'}";
       $DSN .= "; uid=$FORM{'DB_USERNAME'}" if ($FORM{'DB_USERNAME'});
       $DSN .= "; pwd=$FORM{'DB_PASSWORD'}" if ($FORM{'DB_PASSWORD'});
    my $DBH = Win32::ODBC->new($DSN);
    if ($DBH->{'connection'}) {
      print qq~<font color="Green">Connected OK.</font>\n~;
    } else {
      print qq~<font color="Red">Couldn't connect to the data source ($FORM{'DB_NAME'}). ~.&Win32::ODBC::Error().qq~</font>\n~ and &$Exit;
    }
    $DBH->Close();
    
    print qq~</ul>\n~;
  } elsif ($FORM{'DB_TYPE'} eq "oracle") {
    print qq~<li>You chose to use the Oracle database engine.<br>\n~;
    print qq~<ul>\n~;
    print qq~<li>Checking DBI module... ~;
    eval "use DBI";
    if ($@) {
      print qq~<font color="Red">Could not find DBI module. Please check that DBI is available to use on your system and try again.</font>\n~ and &$Exit;
    } else {
      print qq~<font color="Green">Module found.</font>\n~;
    }

    print qq~<li>Checking the Oracle driver... ~;
    my $found = 0;
    my @drivers = DBI->available_drivers();
    foreach my $driver (@drivers) {
      $found = 1 and last if (index($driver, "Oracle") != -1);
    }
    if ($found) {
      print qq~<font color="Green">Driver found.</font>\n~;
    } else {
      print qq~<font color="Red">Could not find an Oracle driver. Please check that an Oracle driver (DBD::Oracle) is available for use on your system and try again.</font>\n~ and &$Exit;
    }

    print qq~<li>Trying to connect to the database... ~;
    $ENV{'ORACLE_HOME'} = $FORM{'DB_SERVER'};
    $ENV{'TNS_ADMIN'}   = $FORM{'DB_PORT'};
    my $DSN  = "DBI:Oracle:$FORM{'DB_NAME'}";
    my $DBH ||= DBI->connect($DSN, $FORM{'DB_USERNAME'}, $FORM{'DB_PASSWORD'});
    if ($DBH) {
      print qq~<font color="Green">Connected OK.</font>\n~;
    } else {
      print qq~<font color="Red">Couldn't connect to the database server and database ($FORM{'DB_NAME'}). $DBI::errstr</font>\n~ and &$Exit;
    }
    $DBH->disconnect();

    print qq~</ul>\n~;
  } else {
    print qq~<li>You chose to use the DBM database engine.<br>\n~;
    print qq~<ul>\n~;
    print qq~<li>Checking for a DBM module... ~;
    my $found = 0;
    foreach my $module ("DB_File", "GDBM_File", "NDBM_File", "SDBM_File") {
      eval "use $module";
      $found = 1 and last unless ($@);
    }
    if ($found) {
      print qq~<font color="Green">Module found.</font>\n~;
    } else {
      print qq~<font color="Red">Could not find a suitable DBM module. Please check that a DBM module (DB_File, GDBM_File, NDBM_File or SDBM_File) is available to use on your system and try again.</font>\n~ and &$Exit;
    }
    print qq~</ul>\n~;
  }

  print qq~<li>Checking to see that SuperLinks.cgi/pl exists... ~;
  if (-e "$FORM{'PATH'}/SuperLinks.cgi" || -e "$FORM{'PATH'}/SuperLinks.pl") {
    print qq~<font color="Green">Found OK.</font>\n~;
  } else {
    print qq~<font color="Olive">File not found. Please check that it exists.</font>\n~;
  }

  if ($SL::EXTENSION ne "cgi" && !(-e "$FORM{'PATH'}/SuperLinks.$SL::EXTENSION") && (-e "$FORM{'PATH'}/SuperLinks.cgi")) {
    print qq~<li>Renaming SuperLinks.cgi to SuperLinks.$SL::EXTENSION... ~;
    if (rename("$FORM{'PATH'}/SuperLinks.cgi", "$FORM{'PATH'}/SuperLinks.$SL::EXTENSION")) {
      print qq~<font color="Green">Renamed OK.</font>\n~;
    } else {
      print qq~<font color="Olive">Couldn't rename file. Please rename it manually.</font>\n~;
    }
  }

  print qq~<li>Checking path to Perl... ~;  
  if (open(INSTALL, "$FORM{'PATH'}/install.$SL::EXTENSION")) {
    my @install = <INSTALL>;
    close(INSTALL);
    my $perlpath = $install[0] || "#!/usr/bin/perl";

    if (open(SUPERLINKS, "$FORM{'PATH'}/SuperLinks.$SL::EXTENSION")) {
      my @superlinks = <SUPERLINKS>;
      close(SUPERLINKS);
  
      if ($superlinks[0] ne $perlpath) {
        print qq~Changing path to Perl in SuperLinks.$SL::EXTENSION... ~;
        if (open(SUPERLINKS, ">$FORM{'PATH'}/SuperLinks.$SL::EXTENSION")) {
          $superlinks[0] = $perlpath;
          print SUPERLINKS join("", @superlinks);
          close(SUPERLINKS);
          print qq~<font color="Green">Done.</font>\n~;
        } else {
          $perlpath =~ s/^#\!//;
          print qq~<font color="Olive">Couldn't write to SuperLinks.$SL::EXTENSION. You will need to change the path to Perl manually to "$perlpath".</font>\n~;
        }
      } else {
        print qq~<font color="Green">Path is OK.</font>\n~;
      }
    } else {
      print qq~<font color="Olive">Couldn't read from SuperLinks.$SL::EXTENSION. You may need to change the path to Perl manually.</font>\n~;
    }
  } else {
    print qq~<font color="Olive">Couldn't read from install.$SL::EXTENSION. You may need to change the path to Perl manually.</font>\n~;
  }

  print qq~</ul>\n~;

  print <<HTML;
<p>The first stage of the installation is complete. Please click the button below to continue:
                                  </td>
                                </tr>
                                <tr class="table-row">
                                  <td colspan="2">
                                    <table border="0" cellspacing="0" cellpadding="0" width="100%">
                                      <tr><td height="2" class="table-divider1"></td></tr>
                                      <tr><td height="1" class="table-divider2"></td></tr>
                                    </table>
                                  </td>
                                </tr>
                                <tr class="table-row">
                                  <td width="200" valign="top" nowrap></td>
                                  <td width="100%"><input type="submit" value="Next >"></td>
                                </tr>
                              </table>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
              <tr>
                <td>
                  <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">
                    <tr class="bottombar">
                      <td><font class="bottombar"></font></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <input type="hidden" name="action" value="CreateTables">
        <input type="hidden" name="FORM_PATH" value="$FORM{'PATH'}">
        <input type="hidden" name="FORM_URL" value="$FORM{'URL'}">
        <input type="hidden" name="FORM_DB_TYPE" value="$FORM{'DB_TYPE'}">
        <input type="hidden" name="FORM_ADMIN_USERNAME" value="$FORM{'ADMIN_USERNAME'}">
        <input type="hidden" name="FORM_ADMIN_PASSWORD" value="$FORM{'ADMIN_PASSWORD'}">
        <input type="hidden" name="FORM_ADMIN_NAME" value="$FORM{'ADMIN_NAME'}">
        <input type="hidden" name="FORM_EMAIL" value="$FORM{'EMAIL'}">
        </form>
      </table>

    </td>
  </tr>
  <tr height="100%">
    <td align="right" valign="bottom"><font class="powered">Powered by <a href="http://www.plasmapulse.com/?sc=SuperLinks">SuperLinks</a> Standard Edition.<br>
      Copyright 2000-2003 &copy; <a href="http://www.plasmapulse.com">PlasmaPulse Solutions</a>. All rights reserved.</font></td>
  </tr>
</table>

</body>

</html>
HTML

  return 1;
}

###############################################################################
# CreateTables subroutine
sub CreateTables {
  my $Exit = eval {
    sub {
      print <<HTML;
                                    </ul>
                                  </td>
                                </tr>
                              </table>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
              <tr>
                <td>
                  <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">
                    <tr class="bottombar">
                      <td><font class="bottombar"></font></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        </form>
      </table>

    </td>
  </tr>
  <tr height="100%">
    <td align="right" valign="bottom"><font class="powered">Powered by <a href="http://www.plasmapulse.com/?sc=SuperLinks">SuperLinks</a> Standard Edition.<br>
      Copyright 2000-2003 &copy; <a href="http://www.plasmapulse.com">PlasmaPulse Solutions</a>. All rights reserved.</font></td>
  </tr>
</table>

</body>

</html>
HTML

      exit;
    }
  };

  my %FORM = (
    "PATH"            => $SL::QUERY{'FORM_PATH'},
    "URL"             => $SL::QUERY{'FORM_URL'},
    "DB_TYPE"         => $SL::QUERY{'FORM_DB_TYPE'},
    "EMAIL"           => $SL::QUERY{'FORM_EMAIL'},
    "ADMIN_USERNAME"  => $SL::QUERY{'FORM_ADMIN_USERNAME'},
    "ADMIN_PASSWORD"  => $SL::QUERY{'FORM_ADMIN_PASSWORD'},
    "ADMIN_NAME"      => $SL::QUERY{'FORM_ADMIN_NAME'}
  );

  print <<HTML;
<html>

<head>
<meta name="GENERATOR" content="SuperLinks, www.plasmapulse.com">
<title>SuperLinks Installation</title>
<style>
  <!--
/* Body Properties */
body {
  padding-left    : 3px;
  padding-right   : 3px;
  padding-bottom  : 3px;
  padding-top     : 3px;
	margin          : 3px;
  background-image: url();
  background-color: #ffffff;
  color           : #000000;
}


/* Font Properties */
font       { font-size: 13px; font-family: Verdana, sans-serif; }
tr         { font-size: 13px; font-family: Verdana, sans-serif; }
font.error { color: Red; }

/* Link Properties */
a         { color: #007ee2; text-decoration: none; }
a:link    { color: #007ee2; }
a:visited { color: #007ee2; }
a:hover   { color: #ff6600; text-decoration: underline; }
a:active  { color: #ff6600; text-decoration: underline; }

/* Main Table Properties */
table.main         { width: 100%; }
table.main-border  { background-color: #82bde9; }
tr.main-background { background-color: #ffffff; }
table.row-border   { background-color: #c6def6; }

/* Title Properties */
tr.title   { background-color: #ecf6ff; }
font.title { font-size: 11px; color: #000000; }

/* Menu Properties */
tr.menu        { background-color: #c6def6; }
font.menu      { font-size: 11px; color: #000000; }

/* "Powered by" Notice Properties */
font.powered { font-size: 10px; }

/* Main Header Properties */
tr.header   { background-image: url([%system.PUBLIC_URL%]/Images/headerbg.gif); background-color: #3b8be1; }
font.header { font-weight: bold; font-size: 13px; color: #ffffff; }

/* Main Dialog Properties */
tr.body { background-color: #ffffff; }

/* Inner Table Properties */
table.table-border { background-color: #a2c8df; }
table.table        { background-color: #ecf6ff; }

/* Inner Header Properties */
tr.table-header   { background-color: #ecf6ff; }
font.table-header { font-weight: bold; font-size: 11px; color: #000000; }

/* Row Properties */
tr.table-row   { background-color: #ffffff; }
font.table-row { font-size: 11px; color: #000000; }

/* Footer Properties */
tr.table-footer   { background-color: #ecf6ff; }
font.table-footer { font-size: 11px; color: #000000; }

/* Bottom Bar Properties */
tr.bottombar { height: 18px; background-color: #ecf6ff; }

/* Form Properties */
font.form-required { font-size: 11px; color: Red; font-weight: bold; }
font.form-subject  { font-size: 11px; font-weight: bold; color: #000000; }
font.form-field    { font-size: 11px; color: #000000; }
font.form-label    { font-size: 11px; color: #000000; }

input, select, textarea { font-family: Verdana, sans-serif; background-color: ; font-size: 11px; color: #000000; }
input.form-textbox, textarea.form-textarea, select.form-selectbox { width: 100%; }

/* Divider Properties */
td.table-divider1 { background-color: #82bde9; }
td.table-divider2 { background-color: #c6def6; }
  //-->
</style>
</head>

<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

<table border="0" cellspacing="0" cellpadding="10" height="100%" class="main">
  <tr height="1">
    <td>

      <table border="0" cellpadding="1" cellspacing="1" width="100%" class="main-border">
        <tr class="main-background">
          <td>
            <table border="0" cellpadding="1" cellspacing="0" width="100%">
              <tr>
                <td>
                  <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">
                    <tr class="header">
                      <td>
                        <table border="0" cellspacing="0" cellpadding="1" width="100%">
                          <tr>
                            <td width="2" nowrap></td>
                            <td width="100%"><font class="header">SuperLinks Installation Process</font></td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
              <tr>
                <td>
                  <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">
                    <tr class="body">
                      <td>
                        <table border="0" cellspacing="1" cellpadding="0" width="100%" class="table-border">
                          <tr>
                            <td>
                              <table border="0" cellspacing="1" cellpadding="6" width="100%" class="table">
                                <tr class="table-row">
                                  <td width="100%" colspan="2">
                                    <ul>
HTML

  print qq~<li>Creating tables...\n~;
  print qq~<ul>\n~;
  
  unshift(@INC, "$FORM{'PATH'}");
  unshift(@INC, "$FORM{'PATH'}/Private");
  unshift(@INC, "$FORM{'PATH'}/Private/Modules");
  unshift(@INC, "$FORM{'PATH'}/Private/Modules/Libraries");
  unshift(@INC, "$FORM{'PATH'}/Private/Variables");

  require "Database.$FORM{'DB_TYPE'}.pm.pl";
  my $DB = Database->new();
  
  print qq~<li>Creating Resources table... ~;
  (
    $DB->CreateTable(
      TABLE       => "Resources",
      VALUE       => {
        ID                  => [ 0, "autonumber",    16, 1,           ""],
        TITLE               => [ 1,     "string",   128, 1,           ""],
        URL                 => [ 2,     "string",   256, 1,           ""],
        CATEGORY            => [ 3,     "number",    16, 1,           ""],
        DESCRIPTION         => [ 4,     "string",   512, 0,           ""],
        IMAGE               => [ 5,     "string",   512, 0,           ""],
        KEYWORDS            => [ 6,     "string",   512, 1,           ""],
        CONTACT_NAME        => [ 7,     "string",   128, 1,           ""],
        CONTACT_EMAIL       => [ 8,     "string",   128, 1,           ""],
        SHOW_EMAIL          => [ 9,     "number",     1, 0,           ""],
        PASSWORD            => [10,     "string",    64, 1,           ""],
        STATUS              => [11,     "number",     1, 0,          "0"],
        WEIGHTING           => [12,     "number",     3, 0,          "0"],
        HITS                => [13,     "number",     8, 0,          "0"],
        CREATE_SECOND       => [14,     "number",     9, 1,           ""],
        CREATE_DATE         => [15,     "string",    64, 1,           ""],
        CREATE_TIME         => [16,     "string",    64, 1,           ""],
        UPDATE_SECOND       => [17,     "number",     9, 0,           ""],
        UPDATE_DATE         => [18,     "string",    64, 0,           ""],
        UPDATE_TIME         => [19,     "string",    64, 0,           ""],
        MAILING_LIST        => [20,     "number",     1, 0,          "0"],
        FLAGS               => [21,     "string", 32768, 0,           ""],
        RATING              => [22,     "number",     8, 0,          "0"],
        REVIEWS             => [23,     "number",     8, 0,          "0"],
        EXTRA               => [24,       "text",    -1, 0,           ""],
        UPLOAD_FILENAME     => [25,     "string",   512, 0,           ""],
        URL_PROTOCOL        => [26,     "string",   256, 1,           ""],
        URL_HOST            => [27,     "string",   256, 1,           ""],
        URL_PORT            => [28,     "number",     6, 0,           ""],
        URL_DIRECTORY       => [29,     "string",   256, 0,           ""],
        URL_FILENAME        => [30,     "string",   256, 0,           ""],
        URL_EXTENSION       => [31,     "string",   256, 0,           ""],
        URL_QUERY           => [32,     "string",   256, 0,           ""]
      },
      PRIMARY_KEY => "ID"
    )
  ) || (print qq~<font color="Red">Error creating table. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Table created OK.</font>\n~;
  
  print qq~<li>Creating Categories table... ~;
  (
    $DB->CreateTable(
      TABLE       => "Categories",
      VALUE       => {
        ID                  => [ 0, "autonumber",    16, 1,           ""],
        TITLE               => [ 1,     "string",    64, 1,           ""],
        DESCRIPTION         => [ 2,     "string",   256, 0,           ""],
        IMAGE               => [ 3,     "string",   512, 0,           ""],
        FULL_TITLE          => [ 4,     "string", 32768, 1,           ""],
        ROOT                => [ 5,     "string", 32768, 1,           ""],
        RESOURCES           => [ 6,     "number",    16, 0,          "0"],
        SKIN                => [ 7,     "string", 32768, 0,           ""],
        EXTRA               => [ 8,       "text",    -1, 0,           ""],
        USER_ADD            => [ 9,     "number",     1, 0,           ""]
      },
      PRIMARY_KEY => "ID"
    )
  ) || (print qq~<font color="Red">Error creating table. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Table created OK.</font>\n~;

  print qq~<li>Creating Rates table... ~;
  (
    $DB->CreateTable(
      TABLE       => "Rates",
      VALUE       => {
        ID                  => [ 0, "autonumber",    16, 1,           ""],
        RID                 => [ 1,     "number",    16, 1,           ""],
        IP                  => [ 2,     "string",    15, 0,           ""]
      },
      PRIMARY_KEY => "ID"
    )
  ) || (print qq~<font color="Red">Error creating table. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Table created OK.</font>\n~;

  print qq~<li>Creating Reviews table... ~;
  (
    $DB->CreateTable(
      TABLE       => "Reviews",
      VALUE       => {
        ID                  => [ 0, "autonumber",    16, 1,           ""],
        RID                 => [ 1,     "number",    16, 1,           ""],
        NAME                => [ 2,     "string",   512, 1,           ""],
        REVIEW              => [ 3,       "text",    -1, 1,           ""],
        IP                  => [ 4,     "string",    15, 0,           ""],
        CREATE_SECOND       => [ 5,     "number",     9, 1,           ""],
        CREATE_DATE         => [ 6,     "string",    64, 1,           ""],
        CREATE_TIME         => [ 7,     "string",    64, 1,           ""]
      },
      PRIMARY_KEY => "ID"
    )
  ) || (print qq~<font color="Red">Error creating table. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Table created OK.</font>\n~;

  print qq~<li>Creating Admins table... ~;
  (
    $DB->CreateTable(
      TABLE       => "Admins",
      VALUE       => {
        USERNAME            => [ 0,     "string",    48, 1,           ""],
        PASSWORD            => [ 1,     "string",    64, 1,           ""],
        NAME                => [ 2,     "string",   128, 1,           ""],
        LEVEL               => [ 3,     "number",    16, 1,           ""],
        STATUS              => [ 4,     "number",     1, 1,           ""]
      },
      PRIMARY_KEY => "USERNAME"
    )
  ) || (print qq~<font color="Red">Error creating table. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Table created OK.</font>\n~;

  print qq~<li>Creating Levels table... ~;
  (
    $DB->CreateTable(
      TABLE       => "Levels",
      VALUE       => {
        ID                  => [ 0, "autonumber",    16, 1,           ""],
        TITLE               => [ 1,     "string",   256, 1,           ""],
        PERMISSIONS         => [ 2,       "text",    -1, 0,           ""]
      },
      PRIMARY_KEY => "ID"
    )
  ) || (print qq~<font color="Red">Error creating table. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Table created OK.</font>\n~;

  print qq~<li>Creating Sessions table... ~;
  (
    $DB->CreateTable(
      TABLE       => "Sessions",
      VALUE       => {
        ID                  => [ 0, "autonumber",    16, 1,           ""],
        USERNAME            => [ 1,     "string",    48, 1,           ""],
        PASSWORD            => [ 2,     "string",    64, 1,           ""],
        IP                  => [ 3,     "string",    16, 1,           ""],
        LOGIN_SECOND        => [ 4,     "number",    10, 1,           ""]
      },
      PRIMARY_KEY => "ID"
    )
  ) || (print qq~<font color="Red">Error creating table. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Table created OK.</font>\n~;

  print qq~<li>Creating Skins table... ~;
  (
    $DB->CreateTable(
      TABLE       => "Skins",
      VALUE       => {
        ID                  => [ 0,     "string",    64, 1,           ""],
        DESCRIPTION         => [ 1,     "string",   256, 1,           ""],
        LOCKED              => [ 2,     "number",     1, 0,           ""],
        STYLESHEET          => [ 3,     "string",    64, 1,           ""],
        TEMPLATESET         => [ 4,     "string",    64, 1,           ""],
        LANGUAGESET         => [ 5,     "string",    64, 1,           ""]
      },
      PRIMARY_KEY => "ID"
    )
  ) || (print qq~<font color="Red">Error creating table. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Table created OK.</font>\n~;

  print qq~<li>Creating StyleSheets table... ~;
  (
    $DB->CreateTable(
      TABLE       => "StyleSheets",
      VALUE       => {
        ID                  => [ 0,     "string",    64, 1,           ""],
        DESCRIPTION         => [ 1,     "string",   256, 1,           ""],
        LOCKED              => [ 2,     "number",     1, 0,           ""],
        STYLESHEET          => [ 3,       "text",    -1, 1,           ""]
      },
      PRIMARY_KEY => "ID"
    )
  ) || (print qq~<font color="Red">Error creating table. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Table created OK.</font>\n~;

  print qq~<li>Creating TemplateSets table... ~;
  (
    $DB->CreateTable(
      TABLE       => "TemplateSets",
      VALUE       => {
        ID                  => [ 0,     "string",    64, 1,           ""],
        DESCRIPTION         => [ 1,     "string",   256, 1,           ""],
        LOCKED              => [ 2,     "number",     1, 0,           ""]
      },
      PRIMARY_KEY => "ID"
    )
  ) || (print qq~<font color="Red">Error creating table. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Table created OK.</font>\n~;

  print qq~<li>Creating LanguageSets table... ~;
  (
    $DB->CreateTable(
      TABLE       => "LanguageSets",
      VALUE       => {
        ID                  => [ 0,     "string",    64, 1,           ""],
        DESCRIPTION         => [ 1,     "string",   256, 1,           ""],
        LOCKED              => [ 2,     "number",     1, 0,           ""]
      },
      PRIMARY_KEY => "ID"
    )
  ) || (print qq~<font color="Red">Error creating table. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Table created OK.</font>\n~;

  print qq~</ul>\n~;

  print qq~<li>Creating Administrators level... ~;
  (
    my $LevelID = $DB->Insert(
      TABLE   => "Levels",
      VALUES  => {
        TITLE       => "Administrator",
        PERMISSIONS => "{ \"SUPERUSER\" => 1 }"
      }
    )
  ) || (print qq~<font color="Red">Error creating level. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Level created OK.</font>\n~;

  print qq~<li>Creating Admin account... ~;
  (
    $DB->Insert(
      TABLE   => "Admins",
      VALUES  => {
        USERNAME    => $FORM{'ADMIN_USERNAME'},
        PASSWORD    => $FORM{'ADMIN_PASSWORD'},
        NAME        => $FORM{'ADMIN_NAME'},
        STATUS      => 1,
        LEVEL       => $LevelID
      }
    )
  ) || (print qq~<font color="Red">Error creating account. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Account created OK.</font>\n~;

  print qq~<li>Creating default Skin... ~;
  (
    $DB->Insert(
      TABLE   => "Skins",
      VALUES  => {
        ID          => "SuperLinks3",
        DESCRIPTION => "SuperLinks 3.x Skin",
        LOCKED      => "1",
        STYLESHEET  => "SuperLinks3",
        TEMPLATESET => "SuperLinks3",
        LANGUAGESET => "Default"
      }
    )
  ) || (print qq~<font color="Red">Error creating skin. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Skin created OK.</font>\n~;

  print qq~<li>Creating default StyleSheet... ~;
  (
    $DB->Insert(
      TABLE   => "StyleSheets",
      VALUES  => {
        ID          => "SuperLinks3",
        DESCRIPTION => "SuperLinks 3.x StyleSheet",
        LOCKED      => "1",
        STYLESHEET  => &myStyleSheet()
      }
    )
  ) || (print qq~<font color="Red">Error creating stylesheet. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">StyleSheet created OK.</font>\n~;

  print qq~<li>Creating default Template Set... ~;
  (
    $DB->Insert(
      TABLE   => "TemplateSets",
      VALUES  => {
        ID          => "SuperLinks3",
        DESCRIPTION => "SuperLinks 3.x Template Set",
        LOCKED      => "1"
      }
    )
  ) || (print qq~<font color="Red">Error creating template set. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Template Set created OK.</font>\n~;

  print qq~<li>Creating default Language Set... ~;
  (
    $DB->Insert(
      TABLE   => "LanguageSets",
      VALUES  => {
        ID          => "Default",
        DESCRIPTION => "Default (English) Language Set",
        LOCKED      => "1"
      }
    )
  ) || (print qq~<font color="Red">Error creating language set. $DB->{'ERROR'}.</font>\n~ and &$Exit);
  print qq~<font color="Green">Language Set created OK.</font>\n~;

  print qq~<li>Removing installation files...\n~;
  print qq~<ul>\n~;
  print qq~<li>Removing install.$SL::EXTENSION... ~;
  if (unlink("$FORM{'PATH'}/install.$SL::EXTENSION")) {
    print qq~<font color="Green">Done.</font>\n~;
  } else {
    print qq~<font color="Olive">Couldn't remove file. Please remove it manually.</font>\n~;
  }
  print qq~<li>Removing Private.tar... ~;
  if (unlink("$FORM{'PATH'}/Private.tar")) {
    print qq~<font color="Green">Done.</font>\n~;
  } else {
    print qq~<font color="Olive">Couldn't remove file. Please remove it manually.</font><br>\n~;
  }
  print qq~<li>Removing Public.tar... ~;
  if (unlink("$FORM{'PATH'}/Public.tar")) {
    print qq~<font color="Green">Done.</font>\n~;
  } else {
    print qq~<font color="Olive">Couldn't remove file. Please remove it manually.</font><br>\n~;
  }
  print qq~<li>Removing Archive/Tar.pm... ~;
  if (unlink("$FORM{'PATH'}/Archive/Tar.pm")) {
    print qq~<font color="Green">Done.</font><br>\n~;
  } else {
    print qq~<font color="Olive">Couldn't remove file. Please remove it manually.</font><br>\n~;
  }
  print qq~<li>Removing Archive directory... ~;
  if (rmdir("$FORM{'PATH'}/Archive")) {
    print qq~<font color="Green">Done.</font>\n~;
  } else {
    print qq~<font color="Olive">Couldn't remove directory. Please remove it manually.</font>\n~;
  }
  print qq~</ul>\n~;
  
  print qq~</ul>\n~;

  print qq~<p><b>Installation should now be complete!</b>~;

  print <<HTML;
<p>You can now <a href="$FORM{'URL'}/SuperLinks.$SL::EXTENSION?CP=1" target="_blank">click here</a> to go straight to the SuperLinks Control Panel.
 We would also greatly appreciate it if you would now take the time to rate SuperLinks using the following dropdown boxes:

<p align="center">
  <table border="0" cellspacing="1" cellpadding="6" class="table"><form method="POST" action="http://cgi-resources.com/rate/index.cgi" target="_blank">
    <tr class="table-header">
      <td colspan="3"><font class="table-header"><a href="http://www.cgi-resources.com" target="_blank">The CGI Resource Index</a></font></td>
    </tr>
    <tr class="table-row">
      <td valign="top" nowrap><font class="form-subject">Rating</font></td>
      <td>
        <select name="rating" style="width: 150">
          <option value="">---
          <option value="10">10 - Best
          <option value="9">9
          <option value="8">8
          <option value="7">7
          <option value="6">6
          <option value="5">5
          <option value="4">4
          <option value="3">3
          <option value="2">2
          <option value="1">1 - Worst
        </select>
      </td>
      <td valign="top" nowrap><input type="submit" value="Rate!"></td>
    </tr>
    <input type="hidden" name="referer" value="http://cgi-resources.com/">
    <input type="hidden" name="link_code" value="05961">
    <input type="hidden" name="category_name" value="Programs and Scripts/Perl/Link Indexing Scripts/Directories and Portals/">
    <input type="hidden" name="link_name" value="SuperLinks">
    </form>
  </table>
</p>

<p align="center">
  <table border="0" cellspacing="1" cellpadding="6" class="table"><form method="POST" action="http://www.hotscripts.com/cgi-bin/rate.cgi" target="_blank">
    <tr class="table-header">
      <td colspan="3"><font class="table-header"><a href="http://www.hotscripts.com" target="_blank">HotScripts</a></font></td>
    </tr>
    <tr class="table-row">
      <td valign="top" nowrap><font class="form-subject">Rating</font></td>
      <td>
        <select name="rate" style="width: 150">
          <option value="">---
          <option value="5">Excellent
          <option value="4">Very Good
          <option value="3">Good
          <option value="2">Fair
          <option value="1">Poor
        </select>
      </td>
      <td valign="top" nowrap><input type="submit" value="Rate!"></td>
    </tr>
    <input type="hidden" name="ID" value="8906">
    </form>
  </table>
</p>
                                  </td>
                                </tr>
                              </table>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
              <tr>
                <td>
                  <table border="0" cellspacing="1" cellpadding="3" width="100%" class="row-border">
                    <tr class="bottombar">
                      <td><font class="bottombar"></font></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>

    </td>
  </tr>
  <tr height="100%">
    <td align="right" valign="bottom"><font class="powered">Powered by <a href="http://www.plasmapulse.com/?sc=SuperLinks">SuperLinks</a> Standard Edition.<br>
      Copyright 2000-2003 &copy; <a href="http://www.plasmapulse.com">PlasmaPulse Solutions</a>. All rights reserved.</font></td>
  </tr>
</table>

</body>

</html>
HTML

  return 1;
}

###############################################################################
# CGIError subroutine
# Prints a CGI error
sub CGIError {
  my ($message, $path) = @_;

  my ($key, $space);

  $message =~ s/\n/<br>/g;

  if ($SL::HTML_HEADER != 1) {
    print "Content-Type: text/html\n\n";
  }

  print "<html>\n";
  print "<head>\n";
  print "<title>CGI Script Error</title>\n";
  print "</head>\n";
  print "<body marginheight=\"5\" marginwidth=\"5\" leftmargin=\"5\" topmargin=\"5\" rightmargin=\"5\">\n";
  print "<font face=\"Verdana\">\n";
  print "<font size=\"4\"><b>CGI Script Error</b></font><p>\n";
  print "<font size=\"2\">\n";

  if ($message) {
    print $message;
  }
  print "<p>";

  print "<font size=\"4\"><b>General Infomation</b></font><p>\n";
  print "<table cellpadding=\"0\" cellspacing=\"0\">\n";

  if ($path) {
    $path =~ s/\\/\//g;
    print "<tr>\n";
    print "<td width=\"200\" valign=\"TOP\"><font face=\"Verdana\" size=\"2\"><b>Error Path</b></font></td>\n";
    print "<td><font face=\"Verdana\" size=\"2\">$path</font></td>\n";
    print "</tr>\n";
  }
  if ($0) {
    $0 =~ s/\\/\//g;
    print "<tr>\n";
    print "<td width=\"200\" valign=\"TOP\"><font face=\"Verdana\" size=\"2\"><b>Script Path</b></font></td>\n";
    print "<td><font face=\"Verdana\" size=\"2\">$0</font></td>\n";
    print "</tr>\n";
  }
  if ($]) {
    print "<tr>\n";
    print "<td width=\"200\" valign=\"TOP\"><font face=\"Verdana\" size=\"2\"><b>Perl Version</b></font></td>\n";
    print "<td><font face=\"Verdana\" size=\"2\">$]</font></td>\n";
    print "</tr>\n";
  }
  if ($CGI::VERSION) {
    print "<tr>\n";
    print "<td width=\"200\" valign=\"TOP\"><font face=\"Verdana\" size=\"2\"><b>CGI.pm Version</b></font></td>\n";
    print "<td><font face=\"Verdana\" size=\"2\">$CGI::VERSION</font></td>\n";
    print "</tr>\n";
  }
  print "</table><p>\n";

  if (defined %SL::QUERY) {
    print "<font size=\"4\"><b>Form Variables</b></font><p>\n";
    print "<table cellpadding=\"0\" cellspacing=\"0\">\n";
    foreach my $KEY (sort keys %SL::QUERY) {
      print "<tr>\n";
      print "<td width=\"200\" valign=\"TOP\"><font face=\"Verdana\" size=\"2\"><b>$KEY</b></font></td>\n";
      print "<td><font face=\"Verdana\" size=\"2\">".$SL::QUERY{$KEY}."</font></td>\n";
      print "</tr>\n";
    }
    print "</table><p>\n";
  }

  print "<font size=\"4\"><b>Environment Variables</b></font><p>\n";
  print "<table cellpadding=\"0\" cellspacing=\"0\">\n";
  foreach $key (sort keys %ENV) {
    print "<tr>\n";
    print "<td width=\"200\" valign=\"TOP\"><font face=\"Verdana\" size=\"2\"><b>$key</b></font></td>\n";
    print "<td><font face=\"Verdana\" size=\"2\">".$ENV{$key}."</font></td>\n";
    print "</tr>\n";
  }
  print "</table><p>\n";

  print "<font size=\"4\"><b>\@INC Contents</b></font><p>\n";
  print "<ul>\n";
  foreach $INC (@INC) {
    print "<li>$INC<br>\n";
  }
  print "</ul><p>\n";
  print "</font>\n";
  print "</font>\n";
  print "</body>\n";
  print "</html>\n";

  exit;
}

###############################################################################
# myStyleSheet subroutine
sub myStyleSheet {
  return <<TEXT;
{
  BODY_PADDING      => "3px",
  BODY_IMAGE        => "",
  BODY_BGCOLOR      => "#ffffff",
  
  FONT_COLOR        => "#000000",
  FONT_SIZE         => "11px",
  FONT_FACE         => "Verdana, sans-serif",
  FONT_ERROR        => "Red",
  
  LINK_COLOR        => "#007ee2",
  LINK_VCOLOR       => "#007ee2",
  LINK_HCOLOR       => "#ff6600",
  LINK_ACOLOR       => "#ff6600",
  
  MAIN_WIDTH        => "100%",
  MAIN_BORDER       => "#82bde9",
  MAIN_BGCOLOR      => "#ffffff",
  MAIN_ROWBORDER    => "#c6def6",
  
  TITLE_BGCOLOR     => "#ecf6ff",
  TITLE_SIZE        => "11px",
  TITLE_COLOR       => "#000000",
  
  MENU_BGCOLOR      => "#c6def6",
  MENU_SIZE         => "11px",
  MENU_COLOR        => "#000000",
  
  LOCATION_SIZE     => "11px",
  LOCATION_COLOR    => "#000000",
  
  HEADER_IMAGE      => "\$SYSTEM->{'PUBLIC_URL'}/Images/headerbg.gif",
  HEADER_BGCOLOR    => "#3b8be1",
  HEADER_SIZE       => "13px",
  HEADER_COLOR      => "#ffffff",
  
  DIALOG_BGCOLOR    => "#ffffff",
  
  INNER_BORDER      => "#a2c8df",
  INNER_BGCOLOR     => "#ecf6ff",
  
  IHEADER_BGCOLOR   => "#ecf6ff",
  IHEADER_SIZE      => "11px",
  IHEADER_COLOR     => "#000000",
  
  ROW_BGCOLOR       => "#ffffff",
  ROW_SIZE          => "11px",
  ROW_COLOR         => "#000000",
  
  FOOTER_BGCOLOR    => "#ecf6ff",
  FOOTER_SIZE       => "11px",
  FOOTER_COLOR      => "#000000",
  
  BOTTOMBAR_HEIGHT  => "18px",
  BOTTOMBAR_BGCOLOR => "#ecf6ff",
  
  REQUIRED_SIZE     => "11px",
  REQUIRED_COLOR    => "Red",
  
  SUBJECT_SIZE      => "11px",
  SUBJECT_COLOR     => "#000000",
  
  FIELD_SIZE        => "11px",
  FIELD_COLOR       => "#000000",
  
  LABEL_SIZE        => "11px",
  LABEL_COLOR       => "#000000",
  
  FORM_FACE         => "Verdana, sans-serif",
  FORM_BGCOLOR      => "",
  FORM_SIZE         => "11px",
  FORM_COLOR        => "#000000",
  FORM_WIDTH        => "100%",
  
  DIVIDER_BGCOLOR1  => "#82bde9",
  DIVIDER_BGCOLOR2  => "#c6def6"
}
TEXT

}

1;